<?php
class Lead_EDO_Datatype_Field_Value implements Lead_EDO_Datatype_Field_Interface
{
    private $_owner;
    private $_config;
    
    private $_messages;
        
    public function __construct($owner, $config)
    {
        $this->_owner = $owner;
        
        // This could be in the column getting very soon... 
        if($config['LENGTH'] == -1)
            $config['LENGTH'] = null;
        
        $this->_config = $config;    
    }
    
    
    public function getOwner()
    {
        return $this->_owner;
    }
    
    
    public function getName()
    {
        return $this->_config['COLUMN_NAME'];
    }
    
    
    
    public function getType()
    {
        return ucfirst(strtolower($this->_config['DATA_TYPE']));
    }
    
    public function isNotNull()
    {
        return (!$this->_config['NULLABLE']);
    }
    
    
    public function getLength()
    {
        return $this->_config['LENGTH'];
    }
    
    
    public function getConfig($key = null)
    {
        if(!$key)
            return $this->_config;
        
        if(isset($this->_config[$key]))
            return $this->_config[$key];
            
        return false;
    }
    
    
    
    public function validate($value)
    {
        return Lead_EDO_datatype_Validator::validate($this, $value);
    }
        
    public function setValue($value, $validate = true)
    {
        if($validate && !$this->validate($value)) {
            return false;
        }
        
        $this->_value = $value;
        return true;
        
        
    }
    
    public function getValue()
    {
        return $this->_value;
    }
    
    
    public function setValidationMessages($messages = array())
    {
        $this->_messages = $messages;
    }
    
    public function getValidationMessages()
    {
        return $this->_messages;
    }
    
    
}